'use strict';
const db = uniCloud.database()
const dbCmd = db.command
function dateToMs(date) {
	var result = new Date(date).getTime();
	return result;
}
function getDay(msTime) {
	var curDate = new Date(msTime);
	var curYear = curDate.getFullYear(); //获取完整的年份(4位,1970-????)
	var curMonth = curDate.getMonth() + 1; //获取当前月份(0-11,0代表1月)
	var curDay = curDate.getDate(); 
	return dateToMs(curYear+'/'+curMonth+'/'+curDay);
}
exports.main = async (event, context) => {
	
	const whereArr = {
		'createTime': dbCmd.gt(0)
	};

	let collection = db.collection('company_collect');
	let res = {};
	
	let countRes = await collection.where(whereArr).count();
	
	// if(event.type==0) {
	// 	return countRes.total;
	// }
	
	let size = 1;
	for(var i=10;i<=10;i++) {
	    const skipCount = i * size;
	    res = await collection.where(whereArr).skip(skipCount).limit(size).orderBy("createTime", "desc").get();
	    if (res.data.length > 0) {
	    	await collection.doc(res.data[0]._id).update({
	    		dayTime:getDay(res.data[0].createTime)
	    	});
	    }
	}
	return {
		status:1,
		total:countRes.total
	};
};
